import React, {Component} from 'react'

class CommentInput extends Component {
  constructor() {
    super()
    this.state = {
      name: '',
      cont: ''
    }
  }
  render() {
    return (
      <div className="comm-in">
        <div className="in-name">
          <span>用户名:</span>
          <input type="text" value={this.state.name} onChange={this.inputName.bind(this)}/>
        </div>
        <div className="in-cont">
          <span>评论内容:</span>
          <textarea name="txt" id="txt" cols="30" rows="10" value={this.state.cont} onChange={this.inputCont.bind(this)}></textarea>
        </div>
        <button className="btn" onClick={this.onSubmit.bind(this)}>发布</button>
      </div>
    )
  }
  inputName(e) {
    this.setState({
      name: e.target.value
    })
  }
  inputCont(e) {
    this.setState({
      cont: e.target.value
    })
  }
  onSubmit() {
    if (this.props.onSubmit) {
      this.props.onSubmit({name: this.state.name, cont: this.state.cont})
    }
    this.setState({
      cont: ''
    })
  }
}

export default CommentInput